package com.hudsonmq.spring.handler.netty;

import com.hudson.codec.domain.RemotingCommand;
import com.hudsonmq.spring.handler.HandlerProcesserManage;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class ProcesserHandler extends SimpleChannelInboundHandler<RemotingCommand> {


    private static final Logger log = LoggerFactory.getLogger(ProcesserHandler.class);

    @Override
    protected void channelRead0(ChannelHandlerContext channelHandlerContext, RemotingCommand remotingCommand) throws Exception {
        HandlerProcesserManage.execute(remotingCommand.getType(), channelHandlerContext, remotingCommand);
        channelHandlerContext.fireChannelRead(remotingCommand);
    }

    @Override
    public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
        log.error("{}", cause.getMessage());
        super.exceptionCaught(ctx, cause);
    }
}
